package com.controller;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePayRequest;
import com.alipay.api.response.AlipayTradePayResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Info;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author zhangqing
 * @Date 2019/6/28 11:30
 **/
@RestController
@Api(tags = "支付寶")
@RequestMapping("/ali")
@Slf4j
public class AliPayController  {
    @PostMapping("/pay")
    @ApiOperation("支付")
    public AlipayTradePayResponse pay() throws Exception {
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", "2016101100661449", "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp1gVtUmMRJZDPBC5EowSGQ3beHo7IQTz6T6vk6sfhLWonnKltpu4LQiDUadBkVKXeg+kIZoZPid8HgCq26/rm2jFuZtV5D/QUlm2Hcto7ibkvX5PhmDCLWWkp6a3USVdq+tLu9wgPR4xtAMaYePemNEdWbNha/3KG4uW2unBQ5sj1MnffXJi/0/qHymGmro1K4MEY9AAPUxxzBgXIyQCDr/aSR/mMhc6A+QXcZRVDgeGKrc6g5x3ZnWW936sVzsXNOBOVa7DmMxF1IzbytoqgjD1tNIR5h3yvb+QPJN0ftPnC+n+moxq88oramONonljL47eoBeUSUDxP9yVQ2Cc6wIDAQAB","json","GBK","MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmGwQLZajkNAInNNuZA/MQ3mOwhnESDOm3Qh6Kp9W2LvFRK3ohz3e67Ddt36SpPj1frqhffXQkxxyICHk8ssCyrE4WumBE2uMKCfitQotdrR89RXLFSlHVg4vcDqkc2J8Y8rZ0AvrKzHArQBEGOERU0xL2xPbPaPAF5GIZMWteu4v/1QM3NYdmeX0FBXxxyl1u45c8Gn09aMG5FAzQLTJ3MJOh76CNUsPHRndj5n2PnDFQHv0zpzb9T/Y7f7rAuT/FEt0A8ilWUXrIMz6yqobcbg048a7osIssrgtbx3/NSkA8yvF0jL8oNLb0ZFR/VphzuEdqrnTGpTcbLdtxTT1jQIDAQAB","RSA2");


        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String date = simpleDateFormat.format(new Date());
        System.out.println(date);
        AlipayTradePayRequest request = new AlipayTradePayRequest();
        request.setBizContent("{" +
                "\"out_trade_no\":\"12312asdfa\"," +
                "\"scene\":\"bar_code\"," +
                "\"auth_code\":\"28763443825664394\"," +
                "\"subject\":\"妈妈的爱\"}");

        AlipayTradePayResponse response = alipayClient.execute(request);
       if(response.isSuccess()){
           log.info("调用成功");
           return response;
       }else{
           log.info("调用失败");
           return response;
       }
    }

    public static void main(String[] args) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String date = simpleDateFormat.format(new Date());
        System.out.println(date);
    }
}
